import { defineStore } from 'pinia'
import {Recordable} from "@/utils/types.ts";
import { loginApi } from "@/api/base/user.ts";
import { router } from "@/router";
import { PageEnum } from "@/enums/pageEnum.ts";

interface UserState {
  accessToken?: string
}

export const useUserStore = defineStore('app-user', {
  state: (): UserState => ({
    accessToken: undefined,
  }),
  actions: {
    async login(params: Recordable): Promise<Recordable | null> {
      const data = await loginApi(params)
      console.log(data, '登录成功')
      this.afterLoginAction()
      return Promise.resolve(null)
    },
    async afterLoginAction() {
      await router.replace(PageEnum.BASE_HOME)
    }
  }
})



